import cv2
from Settings import BaseTestDataCubePath


class VideoEngine:
    def __init__(self, file_path):
        self.__video_engine = cv2.VideoCapture(file_path)

    def readVideoFrame(self):
        ret, frame = self.__video_engine.read()
        return ret, frame

    def showVideoFrame(self, frame):
        cv2.imshow('Video', frame)

    def __dell__(self):
        self.__video_engine.release()
        cv2.destroyAllWindows()

if __name__ == '__main__':
    file_path = f'{BaseTestDataCubePath}/demo.mp4'
    videoEngine = VideoEngine(file_path)
    while True:
        ret, frame = videoEngine.readVideoFrame()
        # 如果读取失败，退出循环
        if not ret:
            print("结束，退出视频")
            break
        # 显示当前帧
        videoEngine.showVideoFrame(frame)

        # 等待用户按键，如果按下'q'键则退出循环
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
